/*
 * 
 * 
 * 
 */
package com.hboxs.asl.entity;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonValue;
import com.hboxs.asl.Constant;
import com.hboxs.asl.interceptor.MemberInterceptor;
import com.hboxs.asl.qcloudLVB.entity.Live;
import com.hboxs.asl.util.DateUtils;
import com.hboxs.asl.wechat.entity.Wechat;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Index;
import org.hibernate.search.annotations.Store;
import org.hibernate.validator.constraints.Email;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotEmpty;

import javax.persistence.*;
import javax.validation.constraints.Digits;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import java.math.BigDecimal;
import java.util.*;

import static javax.persistence.CascadeType.REMOVE;

/**
 * Entity - 会员
 */
@Entity
@Table(name = "xx_member")
@SequenceGenerator(name = "sequenceGenerator", sequenceName = "xx_member_sequence")
public class Member extends BaseEntity {

    private static final long serialVersionUID = 1533130686714725835L;

    /**
     * 身份
     */
    public enum Type {

        /**
         * 用户
         */
        member,

        /**
         * 老师
         */
        teacher;

        private static Map<String, Type> map = new HashMap<>();

        static {
            map.put("普通用户", member);
            map.put("老师", teacher);
        }

        public static Type forValue(String value) {
            return map.get(value);
        }

        @JsonValue
        public String toValue() {
            for (Map.Entry<String, Type> entry : map.entrySet()) {
                if (entry.getValue() == this) {
                    return entry.getKey();
                }
            }

            return "";
        }

        public static Type getDefault() {
            return Type.member;
        }
    }

    private Type type;

    /** 是否置顶 */
    private Boolean isTop;

    public Type getType() {
        return type;
    }

    public void setType(Type type) {
        this.type = type;
    }

    /**
     * "身份信息"参数名称
     */
    public static final String PRINCIPAL_ATTRIBUTE_NAME = MemberInterceptor.class.getName() + ".PRINCIPAL";

    /**
     * "用户名"Cookie名称
     */
    public static final String USERNAME_COOKIE_NAME = "username";

    /**
     * 用户名
     */
    private String username;

    /**
     * 我的收入
     */
    private BigDecimal earnings = BigDecimal.ZERO;

    /**
     * 登录令牌
     */
    private String token;

    /**
     * 登录令牌过期时间
     */
    private Date tokenExpire;

    /**
     * 密码
     */
    private String password;

    /**
     * E-mail
     */
    private String email;

    /**
     * 积分
     */
    private BigDecimal point;

    /**
     * 消费金额
     */
    private BigDecimal amount;

    /**
     * 余额
     */
    private BigDecimal balance;

    /**
     * 是否启用
     */
    private Boolean isEnabled;

    /**
     * 是否锁定
     */
    private Boolean isLocked;

    /**
     * 连续登录失败次数
     */
    private Integer loginFailureCount;

    /**
     * 锁定日期
     */
    private Date lockedDate;

    /**
     * 注册IP
     */
    private String registerIp;

    /**
     * 最后登录IP
     */
    private String loginIp;

    /**
     * 最后登录日期
     */
    private Date loginDate;

    /**
     * 姓名
     */
    private String name;

    /**
     * 出生日期
     */
    private Date birth;

    /**
     * 地址
     */
    private String address;

    /**
     * 邮编
     */
    private String zipCode;

    /**
     * 手机
     */
    private String phone;

    /**
     * 用户标签
     */
    private String tags;

    /**
     * 安全密匙
     */
    private SafeKey safeKey;

    /**
     * 地区
     */
    private Area area;

    /**
     * 会员等级
     */
    private MemberRank memberRank;

    /**
     * 购物车
     */
    private Cart cart;

    /**
     * 临时属性，用于抛出临时字段（获得积分数）
     */
    private BigDecimal tempDistributionPoint;

    /**
     * 临时属性，用于抛出临时字段（订单数）
     */
    private Integer tempDistributionCount;

    /**
     * 订单
     */
    private Set<Order> orders = new HashSet<Order>();

    /**
     * 预存款
     */
    private Set<Deposit> deposits = new HashSet<Deposit>();

    /**
     * 收款单
     */
    private Set<Payment> payments = new HashSet<Payment>();

    /**
     * 优惠码
     */
    private List<CouponCode> couponCodes = new ArrayList<>();

    /**
     * 收货地址
     */
    private Set<Receiver> receivers = new HashSet<Receiver>();

    /**
     * 评论
     */
    private Set<Review> reviews = new HashSet<Review>();

    /**
     * 浏览记录
     */
    private Set<ViewHistory> viewHistorys = new HashSet<>();

    /**
     * 咨询
     */
    private Set<Consultation> consultations = new HashSet<Consultation>();

    /**
     * 收藏商品
     */
    private Set<Product> favoriteProducts = new HashSet<Product>();

    /**
     * 课程
     */
    private Set<Course> courses = new HashSet<>();

    /**
     * 到货通知
     */
    private Set<ProductNotify> productNotifies = new HashSet<ProductNotify>();

    /**
     * 接收的消息
     */
    private Set<Message> inMessages = new HashSet<Message>();

    /**
     * 发送的消息
     */
    private Set<Message> outMessages = new HashSet<Message>();

    /**
     * 接收的私信
     */
    private Set<Letter> inLetters = new HashSet<Letter>();

    /**
     * 发送的私信
     */
    private Set<Letter> outLetters = new HashSet<Letter>();

    /**
     * 我的银行卡
     */
    private List<BankCard> bankCards = new ArrayList<>();

    /**
     * 我的提现记录
     */
    private List<Withdrawal> withdrawals = new ArrayList<>();

    /**
     * 我的分销记录
     */
    private List<PointTrade> pointTrades = new ArrayList<>();

    /**
     * 积分中心操作记录
     */
    private List<CorePointTrade> corePointTrades = new ArrayList<>();

    /**
     * 易问易答交易
     */
    private Set<QuestionTrade> questionTrades = new HashSet<>();

    /**
     * 查看答案支付
     */
    private Set<YiYuanTrade> yiYuanTrades = new HashSet<>();

    /**
     * 课程交易
     */
    private Set<CourseTrade> courseTrades = new HashSet<>();

    /**
     * 微信
     */
    private Wechat wechat;

    /**
     * 头像
     */
    private String avator;

    /**
     * app端唯一标识 clientId
     */
    private String clientId;

    /**
     * 是否接受
     */
    private Boolean accept;

    /**
     * 个推id
     */
    private String appId;

    /**
     * 企业服务
     */
    private Set<EnterpriseService> enterpriseServices = new HashSet<>();

    /**
     * 文章
     */
    private Set<Essay> essays = new HashSet<>();

    /**
     * 财务记录
     */
    private Set<FinancialRecord> financialRecords = new HashSet<>();

    /**
     * 案例
     */
    private Set<Case> cases = new HashSet<>();

    /**
     * 推荐人
     */
    private Member parent;

    /**
     * 下级
     */
    private List<Member> children = new ArrayList<Member>();

    /**
     * 推荐商家
     */
    private Merchant parentMerchant;

    /**
     * 推荐人推荐码
     */
    private String parentCode;

    /**
     * 反馈
     */
    private Set<Feedback> feedbacks = new HashSet<>();

    /**
     * 主播认证
     */
    private MemberCertification memberCertification;

    /**
     * 流水
     */
    private Set<Trade> trades = new HashSet<>();

    /**
     * 推荐码
     */
    private String code;

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    /**
     * 退货记录
     */
    private Set<ReturnsRecord> returnsRecords = new HashSet<>();

    /**
     * 观看中的直播
     */
    private Live watchingLive;

    /**
     * 主播过的直播
     */
    private List<Live> lives = new ArrayList<>();

    /**
     * 点赞直播
     */
    private Set<Live> admireLives = new HashSet<>();

    /**
     * 收藏直播
     */
    private Set<Live> favorLives = new HashSet<>();

    /**
     * 观看过的直播
     */
    private Set<Live> watchedLives = new HashSet<>();

    /**
     * 收藏的主播
     */
    private Set<Member> favorAnchors = new HashSet<>();

    /**
     * 把我收藏的用户
     */
    private Set<Member> favorMembers = new HashSet<>();

    /**
     * 用户购买的礼物记录
     */
    private Set<LiveGiftTrade> liveGiftTradeMembers = new HashSet<>();

    /**
     * 会员的提问
     */
    private List<Question> questions = new ArrayList<>();

    /**
     * 老师回答
     */
    private List<Question> answers = new ArrayList<>();

    /**
     * 游客id
     */
    private String touristId;

    /**
     * 介绍
     */
    private String introduction;

    /**
     * 分类
     */
    private Category category;

    /**
     * 背景图
     */
    public String background;

    public String getTouristId() {
        return touristId;
    }

    public void setTouristId(String touristId) {
        this.touristId = touristId;
    }

    /**
     * 用户主播收到的礼物
     */
    private Set<LiveGiftTrade> liveGiftTradeAnchors = new HashSet<>();

    @OneToMany(mappedBy = "member",fetch = FetchType.LAZY,cascade = REMOVE)
    public Set<ReturnsRecord> getReturnsRecords() {
        return returnsRecords;
    }

    public void setReturnsRecords(Set<ReturnsRecord> returnsRecords) {
        this.returnsRecords = returnsRecords;
    }

    @OneToMany(mappedBy = "buyer",fetch = FetchType.LAZY,cascade = REMOVE)
    public Set<QuestionTrade> getQuestionTrades() {
        return questionTrades;
    }

    public void setQuestionTrades(Set<QuestionTrade> questionTrades) {
        this.questionTrades = questionTrades;
    }

    @OneToMany(mappedBy = "buyer",fetch = FetchType.LAZY,cascade = REMOVE)
    public Set<YiYuanTrade> getYiYuanTrades() {
        return yiYuanTrades;
    }

    public void setYiYuanTrades(Set<YiYuanTrade> yiYuanTrades) {
        this.yiYuanTrades = yiYuanTrades;
    }

    @OneToMany(mappedBy = "buyer",fetch = FetchType.LAZY,cascade = REMOVE)
    public Set<CourseTrade> getCourseTrades() {
        return courseTrades;
    }

    public void setCourseTrades(Set<CourseTrade> courseTrades) {
        this.courseTrades = courseTrades;
    }

    /**
     * 获取流水
     *
     * @return 流水
     */
    @OneToMany(mappedBy = "member", fetch = FetchType.LAZY, cascade = REMOVE)
    public Set<Trade> getTrades() {
        return trades;
    }

    /**
     * 设置流水
     *
     * @param trades
     */
    public void setTrades(Set<Trade> trades) {
        this.trades = trades;
    }

    /**
     * 获取文章
     * @return
     */
    @OneToMany(mappedBy = "member", fetch = FetchType.LAZY, cascade = REMOVE)
    public Set<Essay> getEssays() {
        return essays;
    }

    /**
     * 设置文章
     * @param essays
     */
    public void setEssays(Set<Essay> essays) {
        this.essays = essays;
    }

    @OneToMany(mappedBy = "member", fetch = FetchType.LAZY, cascade = REMOVE)
    public Set<FinancialRecord> getFinancialRecords() {
        return financialRecords;
    }

    public void setFinancialRecords(Set<FinancialRecord> financialRecords) {
        this.financialRecords = financialRecords;
    }

    /**
     * 获取案例
     * @return
     */
    @OneToMany(mappedBy = "member", fetch = FetchType.LAZY, cascade = REMOVE)
    public Set<Case> getCases() {
        return cases;
    }

    /**
     * 设置案例
     * @param cases
     */
    public void setCases(Set<Case> cases) {
        this.cases = cases;
    }

    @OneToMany(mappedBy = "member", fetch = FetchType.LAZY, cascade = REMOVE)
    public Set<EnterpriseService> getEnterpriseServices() {
        return enterpriseServices;
    }

    public void setEnterpriseServices(Set<EnterpriseService> enterpriseServices) {
        this.enterpriseServices = enterpriseServices;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    public Member getParent() {
        return parent;
    }

    public void setParent(Member parent) {
        this.parent = parent;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    public Category getCategory() {
        return category;
    }

    public void setCategory(Category category) {
        this.category = category;
    }

    @OneToMany(mappedBy = "parent", fetch = FetchType.LAZY)
    public List<Member> getChildren() {
        return children;
    }

    public void setChildren(List<Member> children) {
        this.children = children;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    public Merchant getParentMerchant() {
        return parentMerchant;
    }

    public void setParentMerchant(Merchant parentMerchant) {
        this.parentMerchant = parentMerchant;
    }

    public String getParentCode() {
        return parentCode;
    }

    public void setParentCode(String parentCode) {
        this.parentCode = parentCode;
    }

    @OneToOne(mappedBy = "member", fetch = FetchType.LAZY, cascade = REMOVE)
    public MemberCertification getMemberCertification() {
        return memberCertification;
    }

    public void setMemberCertification(MemberCertification memberCertification) {
        this.memberCertification = memberCertification;
    }

    /**
     * 获取用户微信
     *
     * @return
     */
    @OneToOne(mappedBy = "member", cascade = REMOVE)
    public Wechat getWechat() {
        return wechat;
    }

    /**
     * 设置用户微信
     *
     * @param wechat
     */
    public void setWechat(Wechat wechat) {
        this.wechat = wechat;
    }

    /**
     * 获取用户名
     *
     * @return 用户名
     */
    @NotEmpty(groups = Save.class)
    @Pattern(regexp = "^[0-9a-z_A-Z\\u4e00-\\u9fa5]+$")
    @Column(nullable = false, updatable = false, unique = true, length = 100)
    public String getUsername() {
        return username;
    }

    /**
     * 设置用户名
     *
     * @param username 用户名
     */
    public void setUsername(String username) {
        this.username = username;
    }


    /**
     * 获取登录令牌
     *
     * @return
     */
    @JsonProperty
    public String getToken() {
        return token;
    }

    /**
     * 设置登录令牌
     *
     * @param token
     */
    public void setToken(String token) {
        this.token = token;
    }

    /**
     * 获取登录令牌过期时间
     *
     * @return
     */
    public Date getTokenExpire() {
        return tokenExpire;
    }

    /**
     * 设置登录令牌过期时间
     *
     * @param tokenExpire
     */
    public void setTokenExpire(Date tokenExpire) {
        this.tokenExpire = tokenExpire;
    }


    /**
     * 获取密码
     *
     * @return 密码
     */
    @NotEmpty(groups = Save.class)
    @Pattern(regexp = "^[^\\s&\"<>]+$")
    @Column(nullable = false)
    public String getPassword() {
        return password;
    }

    /**
     * 设置密码
     *
     * @param password 密码
     */
    public void setPassword(String password) {
        this.password = password;
    }


    /**
     * 获取E-mail
     *
     * @return E-mail
     */
    @Email
    @Length(max = 200)
    public String getEmail() {
        return email;
    }

    /**
     * 设置E-mail
     *
     * @param email E-mail
     */
    public void setEmail(String email) {
        this.email = email;
    }

    /**
     * 获取积分
     *
     * @return 积分
     */
    @Min(0)
    public BigDecimal getPoint() {
        return point;
    }

    /**
     * 设置积分
     *
     * @param point 积分
     */
    public void setPoint(BigDecimal point) {
        this.point = point;
    }

    /**
     * 获取消费金额
     *
     * @return 消费金额
     */
    public BigDecimal getAmount() {
        return amount;
    }

    /**
     * 设置消费金额
     *
     * @param amount 消费金额
     */
    public void setAmount(BigDecimal amount) {
        this.amount = amount;
    }

    /**
     * 获取余额
     *
     * @return 余额
     */
//    @NotNull(groups = Save.class)
    @Min(0)
    @Digits(integer = 12, fraction = 3)
    @Column(nullable = false, precision = 12, scale = 2)
    public BigDecimal getBalance() {
        return balance;
    }

    /**
     * 设置余额
     *
     * @param balance 余额
     */
    public void setBalance(BigDecimal balance) {
        this.balance = balance;
    }

    /**
     * 获取是否启用
     *
     * @return 是否启用
     */
    @NotNull
    @Column(nullable = false)
    public Boolean getIsEnabled() {
        return isEnabled;
    }

    /**
     * 设置是否启用
     *
     * @param isEnabled 是否启用
     */
    public void setIsEnabled(Boolean isEnabled) {
        this.isEnabled = isEnabled;
    }

    @OneToMany(mappedBy = "member", fetch = FetchType.LAZY, cascade = REMOVE)
    public List<BankCard> getBankCards() {
        return bankCards;
    }

    public void setBankCards(List<BankCard> bankCards) {
        this.bankCards = bankCards;
    }

    @OneToMany(mappedBy = "member", fetch = FetchType.LAZY, cascade = REMOVE)
    public List<Withdrawal> getWithdrawals() {
        return withdrawals;
    }

    public void setWithdrawals(List<Withdrawal> withdrawals) {
        this.withdrawals = withdrawals;
    }

    @OneToMany(mappedBy = "member", fetch = FetchType.LAZY, cascade = REMOVE)
    public List<PointTrade> getPointTrades() {
        return pointTrades;
    }

    public void setPointTrades(List<PointTrade> pointTrades) {
        this.pointTrades = pointTrades;
    }

    @OneToMany(mappedBy = "member", fetch = FetchType.LAZY, cascade = REMOVE)
    public List<CorePointTrade> getCorePointTrades() {
        return corePointTrades;
    }

    public void setCorePointTrades(List<CorePointTrade> corePointTrades) {
        this.corePointTrades = corePointTrades;
    }

    /**
     * 获取是否锁定
     *
     * @return 是否锁定
     */
    @Column(nullable = false)
    public Boolean getIsLocked() {
        return isLocked;
    }

    /**
     * 设置是否锁定
     *
     * @param isLocked 是否锁定
     */
    public void setIsLocked(Boolean isLocked) {
        this.isLocked = isLocked;
    }

    /**
     * 获取连续登录失败次数
     *
     * @return 连续登录失败次数
     */
    @Column(nullable = false)
    public Integer getLoginFailureCount() {
        return loginFailureCount;
    }

    /**
     * 设置连续登录失败次数
     *
     * @param loginFailureCount 连续登录失败次数
     */
    public void setLoginFailureCount(Integer loginFailureCount) {
        this.loginFailureCount = loginFailureCount;
    }

    /**
     * 获取锁定日期
     *
     * @return 锁定日期
     */
    public Date getLockedDate() {
        return lockedDate;
    }

    /**
     * 设置锁定日期
     *
     * @param lockedDate 锁定日期
     */
    public void setLockedDate(Date lockedDate) {
        this.lockedDate = lockedDate;
    }

    /**
     * 获取注册IP
     *
     * @return 注册IP
     */
    @Column(nullable = false, updatable = false)
    public String getRegisterIp() {
        return registerIp;
    }

    /**
     * 设置注册IP
     *
     * @param registerIp 注册IP
     */
    public void setRegisterIp(String registerIp) {
        this.registerIp = registerIp;
    }

    /**
     * 获取最后登录IP
     *
     * @return 最后登录IP
     */
    public String getLoginIp() {
        return loginIp;
    }

    /**
     * 设置最后登录IP
     *
     * @param loginIp 最后登录IP
     */
    public void setLoginIp(String loginIp) {
        this.loginIp = loginIp;
    }

    /**
     * 获取最后登录日期
     *
     * @return 最后登录日期
     */
    public Date getLoginDate() {
        return loginDate;
    }

    /**
     * 设置最后登录日期
     *
     * @param loginDate 最后登录日期
     */
    public void setLoginDate(Date loginDate) {
        this.loginDate = loginDate;
    }

    /**
     * 获取姓名
     *
     * @return 姓名
     */
    @Length(max = 200)
    public String getName() {
        return name;
    }

    /**
     * 设置姓名
     *
     * @param name 姓名
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * 获取出生日期
     *
     * @return 出生日期
     */
    public Date getBirth() {
        return birth;
    }

    /**
     * 设置出生日期
     *
     * @param birth 出生日期
     */
    public void setBirth(Date birth) {
        this.birth = birth;
    }

    /**
     * 获取地址
     *
     * @return 地址
     */
    @Length(max = 200)
    public String getAddress() {
        return address;
    }

    /**
     * 设置地址
     *
     * @param address 地址
     */
    public void setAddress(String address) {
        this.address = address;
    }

    /**
     * 获取邮编
     *
     * @return 邮编
     */
    @Length(max = 200)
    public String getZipCode() {
        return zipCode;
    }

    /**
     * 设置邮编
     *
     * @param zipCode 邮编
     */
    public void setZipCode(String zipCode) {
        this.zipCode = zipCode;
    }

    /**
     * 获取电话
     *
     * @return 电话
     */
    @Length(max = 200)
    public String getPhone() {
        return phone;
    }

    /**
     * 设置电话
     *
     * @param phone 电话
     */
    public void setPhone(String phone) {
        this.phone = phone;
    }

    /**
     * 获取安全密匙
     *
     * @return 安全密匙
     */
    @Embedded
    public SafeKey getSafeKey() {
        return safeKey;
    }

    /**
     * 设置安全密匙
     *
     * @param safeKey 安全密匙
     */
    public void setSafeKey(SafeKey safeKey) {
        this.safeKey = safeKey;
    }

    /**
     * 获取地区
     *
     * @return 地区
     */
    @ManyToOne(fetch = FetchType.LAZY)
    public Area getArea() {
        return area;
    }

    /**
     * 设置地区
     *
     * @param area 地区
     */
    public void setArea(Area area) {
        this.area = area;
    }

    /**
     * 获取会员等级
     *
     * @return 会员等级
     */
    @NotNull
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(nullable = false)
    public MemberRank getMemberRank() {
        return memberRank;
    }

    /**
     * 设置会员等级
     *
     * @param memberRank 会员等级
     */
    public void setMemberRank(MemberRank memberRank) {
        this.memberRank = memberRank;
    }

    /**
     * 获取购物车
     *
     * @return 购物车
     */
    @OneToOne(mappedBy = "member", fetch = FetchType.LAZY, cascade = REMOVE)
    public Cart getCart() {
        return cart;
    }

    /**
     * 设置购物车
     *
     * @param cart 购物车
     */
    public void setCart(Cart cart) {
        this.cart = cart;
    }

    /**
     * 获取订单
     *
     * @return 订单
     */
    @OneToMany(mappedBy = "member", fetch = FetchType.LAZY, cascade = REMOVE)
    public Set<Order> getOrders() {
        return orders;
    }

    /**
     * 设置订单
     *
     * @param orders 订单
     */
    public void setOrders(Set<Order> orders) {
        this.orders = orders;
    }

    /**
     * 获取预存款
     *
     * @return 预存款
     */
    @OneToMany(mappedBy = "member", fetch = FetchType.LAZY, cascade = REMOVE)
    public Set<Deposit> getDeposits() {
        return deposits;
    }

    /**
     * 设置预存款
     *
     * @param deposits 预存款
     */
    public void setDeposits(Set<Deposit> deposits) {
        this.deposits = deposits;
    }

    /**
     * 获取收款单
     *
     * @return 收款单
     */
    @OneToMany(mappedBy = "member", fetch = FetchType.LAZY, cascade = REMOVE)
    public Set<Payment> getPayments() {
        return payments;
    }

    /**
     * 设置收款单
     *
     * @param payments 收款单
     */
    public void setPayments(Set<Payment> payments) {
        this.payments = payments;
    }

    /**
     * 获取优惠码
     *
     * @return 优惠码
     */
    @OneToMany(mappedBy = "member", fetch = FetchType.LAZY, cascade = REMOVE)
    public List<CouponCode> getCouponCodes() {
        return couponCodes;
    }

    /**
     * 设置优惠码
     *
     * @param couponCodes 优惠码
     */
    public void setCouponCodes(List<CouponCode> couponCodes) {
        this.couponCodes = couponCodes;
    }

    /**
     * 获取收货地址
     *
     * @return 收货地址
     */
    @OneToMany(mappedBy = "member", fetch = FetchType.LAZY, cascade = REMOVE)
    @OrderBy("isDefault desc, createDate desc")
    public Set<Receiver> getReceivers() {
        return receivers;
    }

    /**
     * 设置收货地址
     *
     * @param receivers 收货地址
     */
    public void setReceivers(Set<Receiver> receivers) {
        this.receivers = receivers;
    }

    /**
     * 获取评论
     *
     * @return 评论
     */
    @OneToMany(mappedBy = "member", fetch = FetchType.LAZY, cascade = REMOVE)
    @OrderBy("createDate desc")
    public Set<Review> getReviews() {
        return reviews;
    }

    /**
     * 设置评论
     *
     * @param reviews 评论
     */
    public void setReviews(Set<Review> reviews) {
        this.reviews = reviews;
    }

    /**
     * 获取咨询
     *
     * @return 咨询
     */
    @OneToMany(mappedBy = "member", fetch = FetchType.LAZY, cascade = REMOVE)
    @OrderBy("createDate desc")
    public Set<Consultation> getConsultations() {
        return consultations;
    }

    /**
     * 设置咨询
     *
     * @param consultations 咨询
     */
    public void setConsultations(Set<Consultation> consultations) {
        this.consultations = consultations;
    }

    /**
     * 获取收藏商品
     *
     * @return 收藏商品
     */
    @ManyToMany(fetch = FetchType.LAZY)
    @JoinTable(name = "xx_member_favorite_product")
    @OrderBy("createDate desc")
    public Set<Product> getFavoriteProducts() {
        return favoriteProducts;
    }

    /**
     * 设置收藏商品
     *
     * @param favoriteProducts 收藏商品
     */
    public void setFavoriteProducts(Set<Product> favoriteProducts) {
        this.favoriteProducts = favoriteProducts;
    }

    @OneToMany(mappedBy = "member", fetch = FetchType.LAZY, cascade = REMOVE)
    public Set<Course> getCourses() {
        return courses;
    }

    public void setCourses(Set<Course> courses) {
        this.courses = courses;
    }

    /**
     * 获取到货通知
     *
     * @return 到货通知
     */
    @OneToMany(mappedBy = "member", fetch = FetchType.LAZY, cascade = REMOVE)
    public Set<ProductNotify> getProductNotifies() {
        return productNotifies;
    }

    /**
     * 设置到货通知
     *
     * @param productNotifies 到货通知
     */
    public void setProductNotifies(Set<ProductNotify> productNotifies) {
        this.productNotifies = productNotifies;
    }

    /**
     * 获取接收的消息
     *
     * @return 接收的消息
     */
    @OneToMany(mappedBy = "receiver", fetch = FetchType.LAZY, cascade = REMOVE)
    public Set<Message> getInMessages() {
        return inMessages;
    }

    /**
     * 设置接收的消息
     *
     * @param inMessages 接收的消息
     */
    public void setInMessages(Set<Message> inMessages) {
        this.inMessages = inMessages;
    }

    /**
     * 获取发送的消息
     *
     * @return 发送的消息
     */
    @OneToMany(mappedBy = "sender", fetch = FetchType.LAZY, cascade = REMOVE)
    public Set<Message> getOutMessages() {
        return outMessages;
    }

    /**
     * 设置发送的消息
     *
     * @param outMessages 发送的消息
     */
    public void setOutMessages(Set<Message> outMessages) {
        this.outMessages = outMessages;
    }

    @OneToMany(mappedBy = "receiver", fetch = FetchType.LAZY, cascade = REMOVE)
    public Set<Letter> getInLetters() {
        return inLetters;
    }

    public void setInLetters(Set<Letter> inLetters) {
        this.inLetters = inLetters;
    }

    @OneToMany(mappedBy = "sender", fetch = FetchType.LAZY, cascade = REMOVE)
    public Set<Letter> getOutLetters() {
        return outLetters;
    }

    public void setOutLetters(Set<Letter> outLetters) {
        this.outLetters = outLetters;
    }

    /**
     * 获取头像
     *
     * @return the avator
     */
    public String getAvator() {
        if (avator == null || avator.isEmpty()) {
            return null;
        }
        return avator;
    }

    /**
     * 设置头像
     *
     * @param avator the avator to set
     */
    public void setAvator(String avator) {
        this.avator = avator;
    }

    /**
     * 获取app端唯一标识
     *
     * @return
     */
    public String getClientId() {
        return clientId;
    }

    /**
     * 设置app端唯一标识
     *
     * @param clientId
     */
    public void setClientId(String clientId) {
        this.clientId = clientId;
    }

    /**
     * 获取正在观看的直播
     *
     * @return 正在观看的直播
     */
    @ManyToOne(fetch = FetchType.LAZY)
    public Live getWatchingLive() {
        return watchingLive;
    }

    /**
     * 设置正在观看的直播
     *
     * @param watchingLive 正在观看的直播
     */
    public void setWatchingLive(Live watchingLive) {
        this.watchingLive = watchingLive;
    }

    @Transient
    public String getBirthStr() {

        Date birthday = getBirth();
        if (birthday != null) {
            return DateUtils.dateStr(birthday);
        }
        return null;
    }
    /**
     * 获取点赞直播
     *
     * @return 点赞直播
     */
    @ManyToMany(fetch = FetchType.LAZY)
    @JoinTable(name = "xx_member_admire_live")
    @OrderBy("createDate desc")
    public Set<Live> getAdmireLives() {
        return admireLives;
    }

    /**
     * 设置点赞直播
     *
     * @param admireLives 点赞直播
     */
    public void setAdmireLives(Set<Live> admireLives) {
        this.admireLives = admireLives;
    }

    /**
     * 获取收藏直播
     *
     * @return 收藏直播
     */
    @ManyToMany(fetch = FetchType.LAZY)
    @JoinTable(name = "xx_member_favor_live")
    @OrderBy("createDate desc")
    public Set<Live> getFavorLives() {
        return favorLives;
    }

    /**
     * 设置收藏直播
     *
     * @param favorLives 收藏直播
     */
    public void setFavorLives(Set<Live> favorLives) {
        this.favorLives = favorLives;
    }

    /**
     * 获取观看过的直播
     *
     * @return 观看过的直播
     */
    @ManyToMany(mappedBy = "watchedMembers", fetch = FetchType.LAZY)
    public Set<Live> getWatchedLives() {
        return watchedLives;
    }

    /**
     * 设置观看过的直播
     *
     * @param watchedLives 观看过的直播
     */
    @Deprecated
    public void setWatchedLives(Set<Live> watchedLives) {
        this.watchedLives = watchedLives;
    }

    /**
     * 获取收藏的主播
     *
     * @return
     */
    @ManyToMany(fetch = FetchType.LAZY)
    @JoinTable(name = "xx_member_favor_anchor")
    @OrderBy("createDate desc")
    public Set<Member> getFavorAnchors() {
        return favorAnchors;
    }

    /**
     * 设置收藏的主播
     *
     * @param favorAnchors
     */
    public void setFavorAnchors(Set<Member> favorAnchors) {
        this.favorAnchors = favorAnchors;
    }

    @ManyToMany(mappedBy = "favorAnchors", fetch = FetchType.LAZY)
    public Set<Member> getFavorMembers() {
        return favorMembers;
    }

    public void setFavorMembers(Set<Member> favorMembers) {
        this.favorMembers = favorMembers;
    }

    public BigDecimal getTempDistributionPoint() {
        return tempDistributionPoint;
    }

    public void setTempDistributionPoint(BigDecimal tempDistributionPoint) {
        this.tempDistributionPoint = tempDistributionPoint;
    }

    public Integer getTempDistributionCount() {
        return tempDistributionCount;
    }

    public void setTempDistributionCount(Integer tempDistributionCount) {
        this.tempDistributionCount = tempDistributionCount;
    }

    @OneToMany(mappedBy = "member", fetch = FetchType.LAZY, cascade = REMOVE)
    public Set<LiveGiftTrade> getLiveGiftTradeMembers() {
        return liveGiftTradeMembers;
    }

    public void setLiveGiftTradeMembers(Set<LiveGiftTrade> liveGiftTradeMembers) {
        this.liveGiftTradeMembers = liveGiftTradeMembers;
    }

    @OneToMany(mappedBy = "anchor", fetch = FetchType.LAZY, cascade = REMOVE)
    public Set<LiveGiftTrade> getLiveGiftTradeAnchors() {
        return liveGiftTradeAnchors;
    }

    public void setLiveGiftTradeAnchors(Set<LiveGiftTrade> liveGiftTradeAnchors) {
        this.liveGiftTradeAnchors = liveGiftTradeAnchors;
    }

    @OneToMany(mappedBy = "anchor", fetch = FetchType.LAZY, cascade = REMOVE)
    public List<Live> getLives() {
        return lives;
    }

    public void setLives(List<Live> lives) {
        this.lives = lives;
    }

    @OneToMany(mappedBy = "member", fetch = FetchType.LAZY, cascade = REMOVE)
    public Set<ViewHistory> getViewHistorys() {
        return viewHistorys;
    }

    public void setViewHistorys(Set<ViewHistory> viewHistorys) {
        this.viewHistorys = viewHistorys;
    }

    @OneToMany(mappedBy = "member", fetch = FetchType.LAZY, cascade = REMOVE)
    public Set<Feedback> getFeedbacks() {
        return feedbacks;
    }

    public void setFeedbacks(Set<Feedback> feedbacks) {
        this.feedbacks = feedbacks;
    }

    /**
     * 删除前处理
     */
    @PreRemove
    public void preRemove() {
        this.setWatchingLive(null);

        Set<Member> favorAnchors = getFavorAnchors();
        if (favorAnchors != null) {
            for (Member member : favorAnchors) {
                member.getFavorAnchors().clear();
            }
        }

        Set<Member> favorMembers =  getFavorMembers();
        if (favorMembers != null) {
            for (Member member : favorMembers) {
                member.getFavorAnchors().remove(this);
            }
        }

        Set<Live> watchedLives =  getWatchedLives();
        if (watchedLives != null) {
            for (Live live : watchedLives) {
                live.getWatchedMembers().remove(this);
            }
        }
    }

    public String getIntroduction() {
        return introduction;
    }

    public void setIntroduction(String introduction) {
        this.introduction = introduction;
    }

    @OneToMany(mappedBy = "member", fetch = FetchType.LAZY, cascade = REMOVE)
    public List<Question> getQuestions() {
        return questions;
    }

    public void setQuestions(List<Question> questions) {
        this.questions = questions;
    }

    @OneToMany(mappedBy = "teacher", fetch = FetchType.LAZY, cascade = REMOVE)
    public List<Question> getAnswers() {
        return answers;
    }

    public void setAnswers(List<Question> answers) {
        this.answers = answers;
    }

    public String getTags() {
        return tags;
    }

    public void setTags(String tags) {
        this.tags = tags;
    }

    public String getAppId() {
        return appId;
    }

    public void setAppId(String appId) {
        this.appId = appId;
    }

    public BigDecimal getEarnings() {
        return earnings;
    }

    public void setEarnings(BigDecimal earnings) {
        this.earnings = earnings;
    }

    public Boolean getAccept() {
        return accept;
    }

    public void setAccept(Boolean accept) {
        this.accept = accept;
    }

    public String getBackground() {
        return background;
    }

    public void setBackground(String background) {
        this.background = background;
    }

    /**
     * 获取是否置顶
     *
     * @return 是否置顶
     */
    @Field(store = Store.YES, index = Index.UN_TOKENIZED)
    @NotNull
    @Column(nullable = false)
    public Boolean getIsTop() {
        return isTop;
    }

    /**
     * 设置是否置顶
     *
     * @param isTop 是否置顶
     */
    public void setIsTop(Boolean isTop) {
        this.isTop = isTop;
    }

    /**
     * 获取ID
     * @return
     */
    @Transient
    public Long getID() {
        Long ID = super.getId() + Constant.USER_ID;
        return ID;
    }
}